myApp.controller('orderDetailController',function($scope,toaster,$uibModal,$stateParams,$filter,$state,$log,$serOrder){
    var ctrl = this;
    ctrl.vm = {
        data:{},
        data2:{},
        order_id:$stateParams.id,
        comment : '',
        addComment : function () {
            $serOrder.addComment({
                id : ctrl.vm.order_id,
                comment : ctrl.vm.comment
            }).then(function (res) {
                if(res.code==1){
                    ctrl.vm.data = res.data;
                    toaster.info('提示',res.message);
                    ctrl.vm.comment = '';
                    vm.init();
                }else {
                    toaster.info('提示',res.message);
                }
            })
        },
        chengeMoney : function (data) {
            $scope.info = data;
            var modalInstance = $uibModal.open({
                templateUrl: 'chengeMoney.html',
                controller: 'chengeMoneyCtrl',
                windowClass: 'chengeOpen',
                size:'sm',
                resolve: {
                    info: function () {
                        return $scope.info;
                    }
                }
            });
            modalInstance.result.then(function (res) {
                if(res){
                    vm.init();
                }
            }, function () {
                $log.info('Modal dismissed at: ' + new Date());
            });
        }

    };
    var vm ={
        init:function(){
            $serOrder.getIt({
                id:$stateParams.id
            }).then(function(res){
                if(res.code==1){
                    ctrl.vm.data = res.data;
                }else{
                    toaster.info('提示',res.message);
                }
            })
        },
        getDelivery:function(){
            $serOrder.getDelivery({
                id:$stateParams.id
            }).then(function(res){
                if(res.code==1){
                    ctrl.vm.data2 = res.data;
                }else{
                    toaster.info('提示',res.message);
                }
            })
        },
    };
    vm.init();
    vm.getDelivery();
});

myApp.controller('chengeMoneyCtrl', function(info,$scope,$uibModalInstance,$serOrder,$filter, toaster) {
    $scope.newTotal_paid='';
    function init(){
        $serOrder.getIt({
            id:info.base.id
        }).then(function(res){
            if(res.code ==1){
                $scope.total_paid = res.data.base.total_paid;
            }else {
                toaster.pop('info', '信息', res.message);
            }
        });

    }
    init();
    $scope.ok = function () {
        $serOrder.setTotalPaid({
            id : info.base.id,
            total_paid : $scope.newTotal_paid
        }).then(function (res) {
            if(res.code==1){
                toaster.pop('success', '信息', res.message);
                $uibModalInstance.close(true);
            }else if(res.code==0){
                toaster.pop('info', '信息', res.message);
                $uibModalInstance.close(true);
            }else{
                toaster.pop('info', '信息', res.message);
            }

        });
    };
    // $scope.cancel = function () {
    //     $uibModalInstance.dismiss(0);
    // };
});